//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************
//
//
/// \file SpinTracking/src/EventAction.cc
/// \brief Implementation of the SpinTracking::EventAction class

#include "EventAction.hh"
#include "RunAction.hh"


#include "G4Event.hh"
#include "G4RunManager.hh"
#include "G4AnalysisManager.hh"

namespace SpinTracking
{

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

EventAction::EventAction(RunAction* runAction)
: fRunAction(runAction)
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void EventAction::BeginOfEventAction(const G4Event*)
{
  sx = 0;
  sy = 0;
  sz = 0;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void EventAction::EndOfEventAction(const G4Event*)
{
  auto analysisManager = G4AnalysisManager::Instance();
  if(pz != 0){
  analysisManager->FillNtupleDColumn(0, px); // 
  analysisManager->FillNtupleDColumn(1, py);   // 
  analysisManager->FillNtupleDColumn(2, pz);  // 
  analysisManager->FillNtupleDColumn(3, sx0); // 
  analysisManager->FillNtupleDColumn(4, sy0);   // 
  analysisManager->FillNtupleDColumn(5, sz0);  // 
  analysisManager->FillNtupleDColumn(6, sx);
  analysisManager->FillNtupleDColumn(7, sy);
  analysisManager->FillNtupleDColumn(8, sz);   
  analysisManager->AddNtupleRow(0); // 
  }
}


void EventAction::AddInitialMomentum(G4double x, G4double y, G4double z) {
    px = x;
    py = y;
    pz = z;

}

void EventAction::AddInitialSpin(G4double x, G4double y, G4double z){
    sx0 = x;
    sy0 = y;
    sz0 = z;
}


void EventAction::AddSpin(G4double x, G4double y, G4double z){
    sx = x;
    sy = y;
    sz = z;
}


//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

}
